package com.java.service.impl;

import com.java.entity.Answer;
import com.java.mapper.AnswerMapper;
import com.java.mapper.custom.CustomAnswerMapper;
import com.java.service.AnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AnswerServiceImpl implements AnswerService {

    @Autowired
    private CustomAnswerMapper answerMapper;

    @Override
    public int insert(Answer answer) {
        return answerMapper.insertSelective(answer);
    }

    @Override
    public int insertBatch(List<Answer> answers) {
        return answerMapper.insertBatch(answers);
    }

    @Override
    public int delete(Integer answerId) {
        return answerMapper.deleteByPrimaryKey(answerId);
    }

    @Override
    public int update(Answer answer) {
        return answerMapper.updateByPrimaryKeySelective(answer);
    }

    @Override
    public Answer selectOne(Integer answerId) {
        Answer answer = answerMapper.selectByPrimaryKey(answerId);
        if (answer == null) {
            throw new RuntimeException("answer is null, answerId=" + answerId);
        }
        return answer;
    }

    @Override
    public List<Answer> selectAll() {
        return answerMapper.selectByExample(null);
    }

}
